/**
  ******************************************************************************
  * @file   System_config.c
  * @brief  Deploy resources,tasks and services in this file.
  ******************************************************************************
  * @note
  *  - Before running your Task you should first include your headers and init- 
  *    ialize used resources in "System_Resource_Init()". This function will be 
  *    called before tasks Start.
  *    
  *  - All tasks should be created in "System_Tasks_Init()", this function will
  *    be called in 'defaultTask()'.
  *
  ===============================================================================
                                    Task List
  ===============================================================================
  * <table>
  * <tr><th>Task Name     <th>Priority          <th>Frequency/Hz    <th>Stack/Byte
  * <tr><td>              <td>                  <td>                <td>    
  * </table>
  *
 */
/* Includes ------------------------------------------------------------------*/
#include "System_Config.h"
#include "System_DataPool.h"
/* Service */
//#include "Service_Communication.h"
//#include "Service_EngineerChassis.h"
#include "Service_Devices.h"
#include "Service_Debug.h"
/* User support package & SRML */
#include <SRML.h>
#include "SEGGER_SYSVIEW.h"
#include "UpperMonitor.h"
#include "drv_can.h"
#include "PID.h"
#include "drv_timer.h"
/* Private variables ---------------------------------------------------------*/
#include "App_Chassis.h"

/*Founctions------------------------------------------------------------------*/
/**
* @brief Load drivers ,modules, and data resources for tasks.
* @note  Edit this function to add Init-functions and configurations.
*/
void System_Resource_Init(void)
{
		/* Drivers Init ---------------------*/
    Timer_Init(&htim4, USE_HAL_DELAY);
    
    CAN_Init(&hcan1);
		CAN_Rx_Callback_Register(&hcan1,Chassis_Receive_Motor);
    
    Uart_Init(&huart1, Uart1_Rx_Buff, USART1_RX_BUFFER_SIZE,RecHandle); //
    Uart_Init(&huart2, Uart2_Rx_Buff, USART2_RX_BUFFER_SIZE,NULL);
    Uart_Init(&huart3, Uart3_Rx_Buff, USART3_RX_BUFFER_SIZE,NULL);
    Uart_Init(&huart4, Uart4_Rx_Buff, USART4_RX_BUFFER_SIZE,NULL);
    Uart_Init(&huart5, Uart5_Rx_Buff, USART5_RX_BUFFER_SIZE,NULL);
    Uart_Init(&huart6, Uart6_Rx_Buff, USART6_RX_BUFFER_SIZE,Chassis_Receive_HERO);	//
    /* RTOS resources Init --------------*/
    USART_RxPort       = xQueueCreate(4,sizeof(USART_COB));
    USART_TxPort       = xQueueCreate(2,sizeof(USART_COB));
    CAN1_TxPort        = xQueueCreate(4,sizeof(COB_TypeDef));
    CAN2_TxPort        = xQueueCreate(4,sizeof(COB_TypeDef));
    RMMotor_QueueHandle= xQueueCreate(10,sizeof(COB_TypeDef));
    IMU_QueueHandle    = xQueueCreate(2,sizeof(COB_TypeDef));
    NUC_QueueHandle    = xQueueCreate(2,sizeof(USART_COB));
    DR16_QueueHandle   = xQueueCreate(2,sizeof(USART_COB));
    Referee_QueueHandle = xQueueCreate(2,sizeof(USART_COB));
    /* Other resources Init -------------*/
	
  
    /* Modules Init ---------------------*/
    SEGGER_SYSVIEW_Conf();
//    SysLog.getSysTime_regist(HAL_GetTick);
//    SysLog.filter_conf(DEFAULT_TAG, LOG_LVL_ALL,Uart1_Transmit);
//    SysLog.filter_conf("Test Tag", LOG_LVL_ALL, Uart1_Transmit,&Filter_List[0]);
//    SysLog.global_conf(LOG_LVL_ALL, false);

    /* Service configurations -----------*/
		/*
		内部电机can1
		*/

		CAN_Filter_Mask_Config(&hcan1,CanFilter_1|CanFifo_1|Can_STDID|Can_DataType,0x201,0x201);
		CAN_Filter_Mask_Config(&hcan1,CanFilter_2|CanFifo_1|Can_STDID|Can_DataType,0x202,0x202);
		CAN_Filter_Mask_Config(&hcan1,CanFilter_3|CanFifo_1|Can_STDID|Can_DataType,0x203,0x203);
		/*
		设备初始化
		云台
		摩擦轮
		拨盘
		*/
		
		Chassis_Init();
		
		/*
		系统时间初始化
		*/
		myPIDTimer::getMicroTick_regist(Get_SystemTimer);
}  


/**
* @brief Load and start User Tasks. 
* @note  Edit this function to add tasks into the activated tasks list.
*/
void System_Tasks_Init(void)
{ 
    /* Syetem Service init --------------*/
    Service_Debug_Init();
    Service_Devices_Init();
//  Service_TempkateControl_Init();
//  Service_Communication_Init();

    /* Applications Init ----------------*/
   
}


/************************ COPYRIGHT(C) SCUT-ROBOTLAB **************************/

